<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/include/head.jsp"%>
<table id="dg" >
</table>

<div id="queryDialog" class="easyui-dialog" title="查询" style="width: 400px; height: 260px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#searchbb'">  
            <form action="" id="searchForm">
	            <table cellpadding="0" cellspacing="1" class="formtable">
								<tr>
				<td align="right"><label class="Validform_label">送货日期:</label></td>
				<td class="value">
					<input class="easyui-datebox" type="text"  id="sendDate" name="sendDate"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">送货人:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="sender" name="sender"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">备注:</label></td>
				<td class="value">
					<input class="easyui-textbox" type="text"  id="remark" name="remark"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">STATUS:</label></td>
				<td class="value">
					<input class="easyui-numberbox" type="text"  id="status" name="status"/>
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">概要状态:</label></td>
				<td class="value">
					<select id="statusSum" class="easyui-combobox" name="statusSum" style="width:200px;" data-options="required:true">  
					<option value="">所有</option>
					<option value="0,1" selected="selected">未完成</option>  
					<option value="2">已完成</option>    
				</select>
				</td>
				</tr>
	            </table>  
            </form>
            <div style="text-align:right;margin-right:30px;"  id="searchbb">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="btnSearch()">查询</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="btnSearchCancel()">取消</a>  
            </div>                  
</div>
<div id="calDialog" class="easyui-dialog" title="计算" style="width: 400px; height: 260px;"  
                 data-options="iconCls:'pag-list',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,buttons:'#btnimport'">
                 
                 <form action="" id="calForm" method="post"  >
                 <input type="hidden" value="" name="id" id="deliverCalId"></input>
	            <table cellpadding="0" cellspacing="1" class="formtable">
	            <tr>
				<td align="right"><label class="Validform_label">计算方式</label></td>
				<td class="value">
				<select id="usingMaxDis" class="easyui-combobox" name="usingMaxDis" style="width:200px;" data-options="required:true">  
					<option value="true">计算路径(最远开始)</option>
					<option value="false">计算路径(最少路程)</option>
				</select>
				</td>
				</tr>
				
								<tr>
				<td align="right"><label class="Validform_label">出发点:</label></td>
				<td class="value">
				<select id="startLocId" class="easyui-combobox" name="startLocId" style="width:200px;" data-options="required:true">  
				</select>
				</td>
				</tr>
				</table>  
			</form>
<div style="text-align:right;margin-right:30px;"  id="btnimport">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="doCal()">确定</a>  
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="cancelCal()">取消</a>  
 </div>  
</div>                 
<script type="text/javascript">
	var startLoc = [
	 {recvId:"-1",region:"苏州",name:"曙光苑",address:"曙光苑",longitude:"120.576324",latitude:"31.308432"},
	 {recvId:"-5",region:"苏州",name:"馨泰花园",address:"馨泰花园",longitude:"120.558789",latitude:"31.290764"},              
	 {recvId:"-2",region:"苏州",name:"花苑路仓库",address:"花苑路新华工业园",longitude:"120.527812",latitude:"31.267742"},
	 {recvId:"-3",region:"张家港",name:"张家港南湖苑",address:"张家港南湖苑",longitude:"120.558913",latitude:"31.832782"},
	 {recvId:"-4",region:"苏州",name:"虎池路8号",address:"虎池路8号",longitude:"120.566894",latitude:"31.346244"},  
	 {recvId:"-6",region:"苏州",name:"传化公路港",address:"传化公路港",longitude:"120.548011",latitude:"31.360479"} 
	 ];
	$.each(startLoc,function(idx,data){
		$("#startLocId").append("<option value='" + data.recvId + "'>"+ data.name+"</option>");
	});
	function doCal(){
		$.messager.progress(); 
		if(!$("#calForm").form('validate'))
		{
			$.messager.alert("验证结果","未填写数据",'error',function(){
	    	});
			return;
		}
		$("#calForm").form("submit",{
			url:'calSendWay.do',
			onSubmit:function(para){
				var startLocId =  $('#startLocId').combobox('getValue');
				$.each(startLoc,function(idx,data){
					if(data.recvId == startLocId)
					{
						$.extend(para, data);
					}
				});
				return true;
			},
			success:function(data){
				var msg = "";
				var data = eval('(' + data + ')'); // change the JSON string to javascript object
				if(data.result==2)
				{
					msg = "计算失败:" + data.message;
					$.messager.alert("验证结果",msg,'info',function(){
						$.messager.progress('close');
					});
				}
				else
				{
					msg = "计算成功,共" + (data.data.distance/1000) + "公里";
					$.messager.alert("验证结果",msg,'info',function(){
						$.messager.progress('close');
						$('#dg').datagrid('reload');
					});
				}
			}
		});
	}
	function cancelCal()
	{
		$("#calDialog").dialog('close');  
	}
	$(function() {
		initCurdDatagrid('delivery','dg',{
			title:'送货单',
			dwidth:'100%',//弹出对话框的宽度 百分比或者具体数字宽度
			dheight:'100%',//弹出对话框的高度 百分比或者具体数字宽度
			baseUrl:'',
			queryParams:$("#searchForm").serializeObject(),
			sortOrder:'sendDate',
			sortOrder:'desc',
			columns:[[    
				        {field:'sendDate',title:'送货日期',width:100,sortable:true,formatter : formatDate},    
				        {field:'sender',title:'送货人',width:100,sortable:true},    
				        {field:'remark',title:'备注',width:100,sortable:true},    
				        {field:'status',title:'状态',width:100,sortable:true,formatter:formatSendStatus,styler:stylerSendStatus}    
				    ]] 
		},[{
			text: '安排送货', 
	        iconCls: 'icon-submit', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				
				$.messager.progress(); 
				KD.ajax({
	    			url:'submitSending.do',
	    			data:{id:id},
	    			success:function(){
	    				$.messager.alert("验证结果","提交成功",'info',function(){
	    					$('#dg').datagrid('reload');
	    					$.messager.progress('close');
	    				});
	    			}
	    		}); 
				
	        } 
		},'-',{
			text: '送货完成', 
	        iconCls: 'icon-ok', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				
				$.messager.progress(); 
				KD.ajax({
	    			url:'closeDelivery.do',
	    			data:{id:id},
	    			success:function(){
	    				$.messager.alert("验证结果","提交成功",'info',function(){
	    					$.messager.progress('close');
	    					$('#dg').datagrid('reload');
	    				});
	    			}
	    		}); 
				
	        } 
		},'-',{
			text: '取消送货', 
	        iconCls: 'icon-cancel', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				
				$.messager.progress(); 
				KD.ajax({
	    			url:'cancelSending.do',
	    			data:{id:id},
	    			success:function(){
	    				$.messager.alert("验证结果","提交成功",'info',function(){
	    					$.messager.progress('close');
	    					$('#dg').datagrid('reload');
	    				});
	    			}
	    		}); 
				
	        } 
		},'-',{
			text: '计算路径', 
	        iconCls: 'icon-ok', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				$("#deliverCalId").val(id);
				$("#calDialog").dialog('open');
	        } 
		},'-',{
			text: '导出', 
	        iconCls: 'icon-export', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				document.location.href="export.do?id=" + id;
	        } 
		},'-',{
			text: '导出送货单', 
	        iconCls: 'icon-export', 
	        handler: function() { 
	        	var selArr = $('#dg').datagrid('getSelections');
				if(selArr.length != 1)
				{
					$.messager.alert("验证结果","请选中一行数据",'error');
					return;
				}
				var id =  selArr[0].id;
				window.open("${ctx}/ReportServer?reportlet=htje%2F%5B9001%5D%5B8d27%5D%5B5355%5D.cpt&id="+id);
	        } 
		}
		   
		   
		   ]);

	});
	function btnSearchCancel()
	{
		$("#queryDialog").dialog('close');  
	}
	function btnSearch()
	{ 
		$('#dg').datagrid('load',$("#searchForm").serializeObject());
		$("#queryDialog").dialog('close');
	}
	
	function reloadData()
	{
		$('#dg').datagrid('reload');
	}
	
</script>

<%@include file="/include/foot.jsp"%>